package logic

import (
	"context"
	"shopping/model/mysql"

	"shopping/shoppingrpc/internal/svc"
	"shopping/shoppingrpc/shoppingrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsAddLogic) GoodsAdd(in *shoppingrpc.GoodsAddRequest) (*shoppingrpc.GoodsAddResponse, error) {
	// todo: add your logic here and delete this line
	goods := mysql.Goods{
		Name:       in.Name,
		Price:      float64(in.Price),
		Image:      in.Image,
		Stock:      int(in.Stock),
		Status:     int(in.Status),
		CategoryId: int(in.CategoryId),
	}
	mysql.DB.Debug().Create(&goods)

	return &shoppingrpc.GoodsAddResponse{
		Id: int64(goods.ID),
	}, nil
}
